package #(javaGenTool.serviceImplPackagePath);

import #(javaGenTool.servicePackagePath).#(javaGenTool.serviceClassName);
import #(javaGenTool.entityPackagePath).#(javaGenTool.entityClassName);
import #(javaGenTool.boPackagePath).#(javaGenTool.boClassName);
import #(javaGenTool.qoPackagePath).#(javaGenTool.qoClassName);
import #(javaGenTool.voPackagePath).#(javaGenTool.voClassName);
import #(javaGenTool.mapperPackagePath).#(javaGenTool.mapperClassName);
import org.springframework.stereotype.Service;

import com.mybatisflex.core.paginate.Page;
import com.mybatisflex.core.query.QueryWrapper;
import lombok.RequiredArgsConstructor;
import org.dromara.common.core.utils.BeanCopyUtils;

import java.util.List;

/**
 * #(table.getComment()) 服务层实现。
 *
  * @author #(javadocConfig.getAuthor())
  * @since #(javadocConfig.getSince())
 */
@RequiredArgsConstructor
@Service
public class #(javaGenTool.serviceImplClassName)  implements #(javaGenTool.serviceClassName) {

    private final #(javaGenTool.mapperClassName) #(javaGenTool.lowerMapperClassName);

    @Override
    public boolean add(#(javaGenTool.boClassName) #(javaGenTool.lowerBoClassName)) {
        #(javaGenTool.entityClassName) #(javaGenTool.lowerEntityClassName) = BeanCopyUtils.copy(#(javaGenTool.lowerBoClassName), #(javaGenTool.entityClassName).class);
        return #(javaGenTool.lowerMapperClassName).insert(#(javaGenTool.lowerEntityClassName)) > 0;
    }

    @Override
    public boolean remove(Long id) {
        return #(javaGenTool.lowerMapperClassName).deleteById(id) > 0;
    }

    @Override
    public boolean update(#(javaGenTool.boClassName) #(javaGenTool.lowerBoClassName)) {
        #(javaGenTool.entityClassName) #(javaGenTool.lowerEntityClassName) = BeanCopyUtils.copy(#(javaGenTool.lowerBoClassName), #(javaGenTool.entityClassName).class);
        return #(javaGenTool.lowerMapperClassName).update(#(javaGenTool.lowerEntityClassName)) > 0;
    }

    @Override
    public List<#(javaGenTool.voClassName)> list(#(javaGenTool.qoClassName) #(javaGenTool.lowerQoClassName)) {
        #(javaGenTool.entityClassName) #(javaGenTool.lowerEntityClassName) = BeanCopyUtils.copy(#(javaGenTool.lowerQoClassName), #(javaGenTool.entityClassName).class);
        QueryWrapper queryWrapper = QueryWrapper.create(#(javaGenTool.lowerEntityClassName));
        return #(javaGenTool.lowerMapperClassName).selectListByQueryAs(queryWrapper, #(javaGenTool.voClassName).class);
    }

    @Override
    public #(javaGenTool.voClassName) getInfo(@PathVariable Long id) {
        #(javaGenTool.entityClassName) #(javaGenTool.lowerEntityClassName) = #(javaGenTool.lowerMapperClassName).selectOneById(id);
        if (#(javaGenTool.lowerEntityClassName) == null){
            return null;
        }
        return BeanCopyUtils.copy(#(javaGenTool.lowerEntityClassName), #(javaGenTool.voClassName).class);
    }

    @Override
    public Page<#(javaGenTool.voClassName)> page(#(javaGenTool.qoClassName) page) {
        return #(javaGenTool.lowerMapperClassName).paginateAs(page.getPageNumber(), page.getPageSize(), QueryWrapper.create(page), #(javaGenTool.voClassName).class);
    }

}

